import {createRouter, createWebHistory} from 'vue-router'
import Layout from '@/views/layout/index'
import common from "@/router/common";
import user from "@/router/user";
import host from "@/router/host";
import admin from "@/router/admin";
const children = [
    ...user,
    ...host,
    ...admin
]
const routes = [
    {
        path: '/',
        name: 'Home',
        component: Layout,
        children:children
    },
    ...common
]
const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

router.beforeEach((to, from, next) => {
    document.title = to.meta.title ? to.meta.title : '门禁系统'
    next()
})
// router.beforeEach(({name}, from, next) => {
//     // 获取 JWT Token
//     if (localStorage.getItem('Authorization')) {
//         // 如果用户在login页面
//         if (name === 'login') {
//             next('/');
//         } else {
//             next();
//         }
//     } else {
//         if (name === 'login') {
//             next();
//         } else {
//             next({name: 'login'});
//         }
//     }
// })
export default router
